<template>
  <div class="songList">
    <van-sticky offset-top="0.74rem">
      <div class="title">
        <svg class="icon" aria-hidden="true">
          <use xlink:href="#icon-bofang"></use>
        </svg>
        <span class="center"
          >播放全部
          <span>(共{{ dataList.length }}首)</span>
        </span>
        <van-button round type="danger" size="small" color="red"
          >收藏+{{ handelPlayCount.playCountChange(subscribedCount) }}</van-button
        >
      </div>
    </van-sticky>
    <!-- :class="{ leftSpanActive: subscript == index }" -->
    <div class="list">
      <div class="listItem" v-for="(item, index) of dataList" :key="index">
        <div class="itemLeft" @click="musicInfo(item, index)">
          <span class="leftSpan" v-if="!(songItemId == item.id)">{{ index + 1 }}</span>
          <img src="@/assets/loading.gif" alt="" v-if="songItemId == item.id" />
          <div class="leftDiv">
            <p class="divP">{{ item.name }}</p>
            <!-- v-for="(item1, index1) of item.ar" :key="index1"  -->
            <span class="divSpan"> {{ item.ar[0].name }}</span>
          </div>
        </div>
        <div class="itemRight">
          <svg class="iconR" aria-hidden="true" v-if="item.mv != 0">
            <use xlink:href="#icon-shipin"></use>
          </svg>
          <svg class="iconR" aria-hidden="true">
            <use xlink:href="#icon-31liebiao"></use>
          </svg>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { defineProps, withDefaults, getCurrentInstance, computed } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from '@/store'

const router = useRouter()
const store = useStore()
const props = withDefaults(
  defineProps<{
    dataList: any
    subscribedCount: any
  }>(),
  {}
)
//拿到歌曲下标和当前下标做比对比对成功则添加类名实现特效
const songItemId = computed(() => store.state.songList.songItem.id)
const handelPlayCount =
  getCurrentInstance()?.appContext.app.config.globalProperties.$handelPlayCount

//点击拿到歌曲的全部信息,再去请求歌词
const queryInfo = {
  pageName: '/lyric',
  id: '',
  loading: false
}
const musicInfo = (item: any, index: any) => {
  queryInfo.id = item.id
  const songItem = item
  const songItemAl = item.al
  const songItemIndex = index
  store.commit('songList/changeSongItemInfo', { songItem, songItemAl, songItemIndex })
  store.dispatch('songList/getSongInfoList', queryInfo)
}
</script>

<style scoped lang="less">
.songList {
  width: 100%;
  border: 1px solid #fff;
  box-sizing: border-box;
  border-top-left-radius: 0.2rem;
  border-top-right-radius: 0.2rem;
  background-color: #fff;
  overflow: hidden;
  .title {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    padding: 0 0.2rem;
    background-color: #fff;

    .center {
      position: absolute;
      left: 0.8rem;
    }
  }
  .list {
    .listItem {
      height: 1rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .itemLeft {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .leftSpan {
          display: block;
          width: 0.6rem;
          height: 0.5rem;
          text-align: center;
          line-height: 0.5rem;
        }

        .leftDiv {
          display: flex;
          flex-direction: column;
          justify-items: center;

          padding-left: 0.2rem;
          .divP {
            width: 5rem;
            font-weight: 900;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
          .divSpan {
            font-weight: normal;
            color: rgb(135, 134, 134);
          }
        }
      }
      .itemRight {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-right: 0.2rem;
        .iconR {
          width: 0.5rem;
          height: 0.5rem;
          padding: 0.05rem;
        }
      }
    }
    .listItem:active {
      background-color: rgba(232, 229, 229, 0.5);
    }
  }
}
</style>
